<!--
(c) Copyright Cory Plotts.
This source is subject to the Microsoft Public License (Ms-PL).
Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
All other rights reserved.
-->
<my:Inspector
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	x:Class="Snoop.PropertyGrid2"
	xmlns:my="clr-namespace:Snoop"
	xmlns:editors="clr-namespace:Snoop.ValueEditors"
	x:Name="PropertyGrid"
	MinHeight="0"
	MinWidth="0"
>
	<Grid.Resources>
		<ResourceDictionary>
			<ContextMenu x:Key="PropertyMenu">
				<MenuItem Command="{x:Static my:PropertyInspector.DelveCommand}" CommandParameter="{Binding}">
					<MenuItem.Header>
						<TextBlock Style="{x:Null}" Text="Delve"/>
					</MenuItem.Header>
				</MenuItem>
				<MenuItem Command="{x:Static my:PropertyInspector.DelveBindingCommand}" CommandParameter="{Binding}">
					<MenuItem.Header>
						<TextBlock Style="{x:Null}" Text="Delve Binding"/>
					</MenuItem.Header>
				</MenuItem>
				<MenuItem Command="{x:Static my:PropertyInspector.DelveBindingExpressionCommand}" CommandParameter="{Binding}">
					<MenuItem.Header>
						<TextBlock Style="{x:Null}" Text="Delve BindingExpression"/>
					</MenuItem.Header>
				</MenuItem>
				<MenuItem Command="{x:Static my:PropertyGrid2.ShowBindingErrorsCommand}" CommandParameter="{Binding}">
					<MenuItem.Header>
						<TextBlock Style="{x:Null}" Text="Display Binding Errors"/>
					</MenuItem.Header>
				</MenuItem>
				<MenuItem Command="{x:Static my:PropertyGrid2.ClearCommand}" CommandParameter="{Binding}">
					<MenuItem.Header>
						<TextBlock Style="{x:Null}" Text="Clear/Reset"/>
					</MenuItem.Header>
				</MenuItem>
				<MenuItem Command="{x:Static my:PropertyInspector.SnipXamlCommand}" CommandParameter="{Binding}">
					<MenuItem.Header>
						<TextBlock Style="{x:Null}" Text="Copy this brush"/>
					</MenuItem.Header>
				</MenuItem>
			</ContextMenu>

			<Style TargetType="{x:Type GridViewColumnHeader}">
				<Setter Property="Command" Value="{x:Static my:PropertyGrid2.SortCommand}"/>
			</Style>
			
			<Style TargetType="{x:Type editors:MouseWheelValueEditor}">
				<Setter Property="DockPanel.Dock" Value="Right"/>
				<Setter Property="Margin" Value="5,0,0,0"/>
				<Setter Property="Visibility" Value="Collapsed"/>
				<Setter Property="ToolTip">
					<Setter.Value>
                        <DataTemplate>
                            <TextBlock Style="{x:Null}" Text="Scroll mouse wheel here to edit value"/>
                        </DataTemplate>
					</Setter.Value>
				</Setter>
				<Style.Triggers>
					<MultiDataTrigger>
						<MultiDataTrigger.Conditions>
							<Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListViewItem}}}" Value="True"/>
							<Condition Binding="{Binding CanEdit}" Value="True"/>
						</MultiDataTrigger.Conditions>
						<Setter Property="Visibility" Value="Visible"/>
					</MultiDataTrigger>
				</Style.Triggers>
			</Style>

			<ControlTemplate x:Key="BreakpointTemplate" TargetType="{x:Type CheckBox}">
				<Grid>
					<Image Name="Icon" Source="{DynamicResource noBreakpointDrawingImage}" Width="12" Height="12"/>
				</Grid>
				<ControlTemplate.Triggers>
					<Trigger Property="IsChecked" Value="True">
						<Setter Property="Source" Value="{DynamicResource breakpointDrawingImage}" TargetName="Icon"/>
					</Trigger>
				</ControlTemplate.Triggers>
			</ControlTemplate>

			<my:ValueEditorTemplateSelector x:Key="EditorSelector">
				<my:ValueEditorTemplateSelector.StandardTemplate>
					<DataTemplate>
						<DockPanel>
							<!-- add mouse wheel editor to right of value (only visible when IsSelected and CanEdit) -->
							<editors:MouseWheelValueEditor/>

							<my:StandardValueEditor
								PropertyType="{Binding PropertyType}"
								Value="{Binding Value, Mode=TwoWay}"
								DescriptiveValue="{Binding DescriptiveValue, Mode=OneWay}"
								IsSelected="{Binding IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListViewItem}}}"
								IsEditable="{Binding CanEdit}"
								PropertyInfo="{Binding}"
							/>

							<!-- to allow ValueEditor to live on the left and not stretch -->
							<Border/>
						</DockPanel>
					</DataTemplate>
				</my:ValueEditorTemplateSelector.StandardTemplate>

				<my:ValueEditorTemplateSelector.EnumTemplate>
					<DataTemplate>
						<DockPanel>
							<!-- add mouse wheel editor to right of value (only visible when IsSelected and CanEdit) -->
							<editors:MouseWheelValueEditor/>

							<my:EnumValueEditor
								PropertyType="{Binding PropertyType}"
								Value="{Binding Value, Mode=TwoWay}"
								DescriptiveValue="{Binding DescriptiveValue, Mode=OneWay}"
								IsSelected="{Binding IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListViewItem}}}"
								IsEditable="{Binding CanEdit}"
								PropertyInfo="{Binding}"
							/>

							<!-- to allow ValueEditor to live on the left and not stretch -->
							<Border/>
						</DockPanel>
					</DataTemplate>
				</my:ValueEditorTemplateSelector.EnumTemplate>

				<my:ValueEditorTemplateSelector.BoolTemplate>
					<DataTemplate>
						<DockPanel>
							<!-- add mouse wheel editor to right of value (only visible when IsSelected and CanEdit) -->
							<editors:MouseWheelValueEditor/>

							<my:BoolValueEditor
								PropertyType="{Binding PropertyType}"
								Value="{Binding Value, Mode=TwoWay}"
								DescriptiveValue="{Binding DescriptiveValue, Mode=OneWay}"
								IsSelected="{Binding IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListViewItem}}}"
								IsEditable="{Binding CanEdit}"
								PropertyInfo="{Binding}"
							/>

							<!-- to allow ValueEditor to live on the left and not stretch -->
							<Border/>
						</DockPanel>
					</DataTemplate>
				</my:ValueEditorTemplateSelector.BoolTemplate>

				<my:ValueEditorTemplateSelector.BrushTemplate>
					<DataTemplate>
						<DockPanel>
							<!-- add mouse wheel editor to right of value (only visible when IsSelected and CanEdit) -->
							<editors:MouseWheelValueEditor/>

							<my:BrushValueEditor
								PropertyType="{Binding PropertyType}"
								Value="{Binding Value, Mode=TwoWay}"
								DescriptiveValue="{Binding DescriptiveValue, Mode=OneWay}"
								IsSelected="{Binding IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListViewItem}}}"
								IsEditable="{Binding CanEdit}"
								PropertyInfo="{Binding}"
							/>

							<!-- to allow ValueEditor to live on the left and not stretch -->
							<Border/>
						</DockPanel>
					</DataTemplate>
				</my:ValueEditorTemplateSelector.BrushTemplate>
			</my:ValueEditorTemplateSelector>

			<DataTemplate x:Key="ValueSourceTemplate">
				<TextBlock Style="{x:Null}" Text="{Binding ValueSource.BaseValueSource}" Height="16">
					<TextBlock.ToolTip>
						<TextBlock Style="{x:Null}" Text="{Binding ValueSource.BaseValueSource}"/>
					</TextBlock.ToolTip>
				</TextBlock>
			</DataTemplate>
		</ResourceDictionary>
	</Grid.Resources>

	<Grid.RowDefinitions>
		<RowDefinition Height="*"/>
	</Grid.RowDefinitions>

	<ListView
		x:Name="ListView"
		Grid.RowSpan="2"
		MinHeight="0"
		MinWidth="0"
		HorizontalContentAlignment="Stretch"
		ItemsSource="{Binding ElementName=PropertyGrid, Path=Properties}"
		SelectedItem="{Binding ElementName=PropertyGrid, Path=Selection, Mode=TwoWay}"
		IsSynchronizedWithCurrentItem="True"
        AlternationCount="2"
	>
		<!-- cplotts note: -->
		<!-- does turning virtualization off actually improve performance? let's play with this later. -->
		<!--
		<ListView.ItemsPanel>
			<ItemsPanelTemplate>
				<StackPanel/>
			</ItemsPanelTemplate>
		</ListView.ItemsPanel>
		-->

		<ListView.ItemContainerStyle>
			<Style TargetType="{x:Type ListViewItem}">
				<Setter Property="ContextMenu" Value="{StaticResource PropertyMenu}"/>
				<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
				<Style.Triggers>

                    <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                        <Setter Property="Background" Value="Transparent"></Setter>
                    </Trigger>
                    <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                        <Setter Property="Background" Value="#FFEAEAEA"></Setter>
                    </Trigger>
                    
                    <DataTrigger Binding="{Binding IsLocallySet}" Value="False">
						<Setter Property="Foreground" Value="Gray"/>
					</DataTrigger>
					<!--<DataTrigger Binding="{Binding IsOdd}" Value="False">
						<Setter Property="Background" Value="#FFEAEAEA"/>
					</DataTrigger>-->
					<DataTrigger Binding="{Binding IsExpression}" Value="True">
						<Setter Property="Background" Value="LightGreen"/>
					</DataTrigger>
					<DataTrigger Binding="{Binding IsAnimated}" Value="True">
						<Setter Property="Background" Value="LightSalmon"/>
					</DataTrigger>
					<DataTrigger Binding="{Binding IsInvalidBinding}" Value="True">
						<Setter Property="Background" Value="Red"/>
						<Setter Property="Foreground" Value="White"/>
					</DataTrigger>
					<Trigger Property="IsSelected" Value="True">
						<Setter Property="Background" Value="LightGray"/>
					</Trigger>
					<DataTrigger Binding="{Binding HasChangedRecently}" Value="True">
						<Setter Property="Background" Value="Yellow"/>
					</DataTrigger>
				</Style.Triggers>
			</Style>
		</ListView.ItemContainerStyle>
		<ListView.View>
			<GridView>
				<GridViewColumn Width="25">
					<GridViewColumn.CellTemplate>
						<DataTemplate>
							<CheckBox IsChecked="{Binding BreakOnChange}" Template="{StaticResource BreakpointTemplate}">
								<CheckBox.ToolTip>
									<TextBlock Style="{x:Null}" Text="Click here to toggle a debug breakpoint on and off."/>
								</CheckBox.ToolTip>
							</CheckBox>
						</DataTemplate>
					</GridViewColumn.CellTemplate>
				</GridViewColumn>

				<GridViewColumn Width="200">
					<GridViewColumn.Header>
						<TextBlock Style="{x:Null}" Text="Name">
							<TextBlock.ToolTip>
								<TextBlock Style="{x:Null}" Text="The name of the property"/>
							</TextBlock.ToolTip>
						</TextBlock>
					</GridViewColumn.Header>
					<GridViewColumn.CellTemplate>
						<DataTemplate>
							<TextBlock Style="{x:Null}" Text="{Binding DisplayName}" Height="15" MouseLeftButtonDown="HandleNameClick">
								<TextBlock.ToolTip>
									<TextBlock Style="{x:Null}" Text="{Binding DisplayName}"/>
								</TextBlock.ToolTip>
							</TextBlock>
						</DataTemplate>
					</GridViewColumn.CellTemplate>
				</GridViewColumn>

				<GridViewColumn Width="175" CellTemplateSelector="{StaticResource EditorSelector}">
					<GridViewColumn.Header>
						<TextBlock Style="{x:Null}" Text="Value">
							<TextBlock.ToolTip>
								<TextBlock Style="{x:Null}" Text="The value of the property"/>
							</TextBlock.ToolTip>
						</TextBlock>
					</GridViewColumn.Header>
				</GridViewColumn>

				<GridViewColumn Width="143">
					<GridViewColumn.Header>
						<TextBlock Style="{x:Null}" Text="Value Source">
							<TextBlock.ToolTip>
								<StackPanel>
									<TextBlock Style="{x:Null}" Text="This is the value source of the property,"/>
									<TextBlock Style="{x:Null}" Text="i.e. from where the property gets its value."/>
								</StackPanel>
							</TextBlock.ToolTip>
						</TextBlock>
					</GridViewColumn.Header>
					<GridViewColumn.CellTemplate>
						<DataTemplate>
							<ContentControl x:Name="ContentHost" Content="{Binding}" ContentTemplate="{StaticResource ValueSourceTemplate}"/>
						</DataTemplate>
					</GridViewColumn.CellTemplate>
				</GridViewColumn>

				<GridViewColumn Width="200">
					<GridViewColumn.Header>
						<TextBlock Style="{x:Null}" Text="Binding Errors">
							<TextBlock.ToolTip>
								<StackPanel>
									<TextBlock Style="{x:Null}" Text="This column gives additional info on any binding errors."/>
									<TextBlock Style="{x:Null}" Text="Note: the row for any property with binding errors will"/>
									<TextBlock Style="{x:Null}" Text="have a red background."/>
								</StackPanel>
							</TextBlock.ToolTip>
						</TextBlock>
					</GridViewColumn.Header>
					<GridViewColumn.CellTemplate>
						<DataTemplate>
							<TextBlock Style="{x:Null}" Text="{Binding BindingError}" Height="15">
								<TextBlock.ToolTip>
									<TextBlock Style="{x:Null}" Text="{Binding BindingError}"/>
								</TextBlock.ToolTip>
							</TextBlock>
						</DataTemplate>
					</GridViewColumn.CellTemplate>
				</GridViewColumn>
			</GridView>
		</ListView.View>
	</ListView>
</my:Inspector>